import sun.misc.Launcher;
import sun.misc.URLClassPath;
import sun.net.spi.nameservice.dns.DNSNameService;

import java.net.URL;

/**
 * @author <a href='mailto:maruichao52@gmail.com'>MRC</a>
 * @since 2021/4/21
 */
public class PrintClassLoader {

    public static void main(String[] args) {

        String desc = "123";
        // string class loader
        System.out.println(String.class.getClassLoader());
        System.out.println(DNSNameService.class.getClassLoader());
        System.out.println(PrintClassLoader.class.getClassLoader());

        System.out.println("--------------------");
        ClassLoader loader = ClassLoader.getSystemClassLoader();
        System.out.println("SystemClassLoader=" + loader);

        ClassLoader parent = loader.getParent();
        System.out.println("ExtClassLoader=" + parent);

        ClassLoader bootstrap = parent.getParent();
        System.out.println("bootstrap=" + bootstrap);

        System.out.println("--------------------");

        URLClassPath urlClassPath = Launcher.getBootstrapClassPath();
        ClassLoader defaultLoader = Launcher.getLauncher().getClassLoader();
        System.out.println("defaultLoader=" + defaultLoader);

        System.out.println("bootstrap class path");
        for (URL url : urlClassPath.getURLs()) {
            System.out.println(url.toExternalForm());
        }
        System.out.println("--------------------ext class loaded class path");
        System.out.println(System.getProperty("java.ext.dirs"));

        System.out.println("--------------------app class loaded class path");
        System.out.println(System.getProperty("java.class.path"));
    }

}
